package com.example.demo.util;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                //跨域请求的端口号
                .allowedOrigins("Http://localhost:8080","null")
                //可跨域请求的方法
                .allowedMethods("GET","POST","PUT","OPTIONS","DELETE")
                //允许携带信息-token
                .allowCredentials(true)
                //最大访问时间
                .maxAge(3600);
    }
}